import json
import time
from .gegtPublicData import *

def getPriceSortData():
    cars = list(getAllCars())
    priceSortList = {
        '0-5W':0,
        '5-10W':0,
        '10-20W':0,
        '20-30W':0,
        '30W以上':0,
    }
    for car in cars:
        s = [json.loads(car.price)[0]][0]
        if s < 5 :
            priceSortList['0-5W'] += 1
        elif s >= 5 and s < 10 :
            priceSortList['5-10W'] += 1
        elif s >= 10 and s < 20 :
            priceSortList['10-20W'] += 1
        elif s >= 20 and s < 30 :
            priceSortList['20-30W'] += 1
        else:
            priceSortList['30W以上'] += 1
    # print(priceSortList)   #以name 、 value 存储
    realData = []
    for k,v in priceSortList.items():
        realData.append({
            'name':k,
            'value':v
        })
    return realData